<?php

/**
 * Created by PhpStorm.
 * User: xiaoqiang
 * Date: 15-3-22
 * Time: 下午1:23
 */
class LibRoute extends LibBase
{

    static public function init()
    {
        if (defined("CLI_URL")) {
            $request = CLI_URL;
        } else {
            $request = $_SERVER['REQUEST_URI']; //$_GET['_RW_'];            
        }
        $class = '\Library\route\Lib' . ucfirst(ROUTE_MODEL);
        if (!class_exists($class)) {
            return LibLog::toDb("路由方法" . ROUTE_MODEL . "不可用,请检查");
        }
        if (PREFIX_STATIC) {
            $request = preg_replace('/\.html$/', "", $request);
        }
        if ($request == '/') {
            $request = '/home';
        }
        /**
         * @var \Library\route\LibBase $class
         */
        $class::getInstance()->init($request);
        return true;
    }

    /**
     * 设置路由模式
     * @param $model
     */
    static public function setRouteModel($model)
    {
        define('ROUTE_MODEL', $model);
    }
} 